<?php

if (!defined('FRAMEWORKS_RB_FUNCTIONS_ADD')):
define('FRAMEWORKS_RB_FUNCTIONS_ADD', true);

function rb_add_attr( $coll ) {
	$str = '';
	foreach ( $coll as $name => $val ) {
		if ( $name != '_' ) {
			$str .= ' ' . $name . '="' . htmlspecialchars( $val, ENT_QUOTES ) . '"';
		}
	}
	return $str;
}
	
function rb_add_url( $url ) {
	if ( substr( $url, 0, 7 ) == 'http://' ) {
		return $url;
	}
	if ( substr( $url, 0, 1 ) == '/' ) {
		$url = substr( $url, 1 );
	}
	$url = XOOPS_URL.'/'.$url;
	return $url;
}
	
function rb_add_script( $src = '', $attr = array(), $content = '' ) {
	global $xoopsTpl, $xoTheme;
	if ($xoTheme) {
		if ( empty( $src ) ) $src = null;
		if ( empty( $attr ) ) $attr = array( 'type' => 'text/javascript' );
		$xoTheme->addScript($src, $attr, $content);
	} else {
		if ( empty( $attr ) )     		$attr = array();
		if ( !isset( $attr['type'] ) ) 	$attr['type'] = 'text/javascript';
		if ( !empty( $src ) ) 			$attr['src'] = rb_add_url($src);
		if ( !empty( $content ) )		$attr['_'] = $content;
		$str = '<script'.rb_add_attr( $attr ).'>';
		if ( @$attr['_'] ) {
			$str .= "\n//<![CDATA[\n".$attr['_']."\n//]]>\n";
		}
		$str .= '</script>';
			
		$module_header = $xoopsTpl->get_template_vars('xoops_module_header') ;
		$xoopsTpl->assign( 'xoops_module_header', $module_header."\n".$str );
	}
}
	
	
function rb_add_stylesheet( $src = '', $attr = array(), $content = '' ) {
	global $xoopsTpl, $xoTheme;
	if ( empty( $attr ) )     		$attr = array();
	if ( !isset($attr['type']) ) 	$attr['type'] = 'text/css';
	if ($xoTheme) {
		$xoTheme->addStylesheet($src, $attr, $content);
	} else {
		if ( !empty( $src ) ) 			$attr['href'] = rb_add_url($src);
		if ( !empty( $content ) ) 		$attr['_'] = $content;
			
		if ( @$attr['_'] ) {
			$str = '<style' . rb_add_attr($attr) . ">\n/* <![CDATA[ */\n" . $attr['_'] . "\n/* //]]> */\n</style>";
		} else {
			$str = '<link rel="stylesheet"'.rb_add_attr($attr).' />';
		}
		
		$module_header = $xoopsTpl->get_template_vars('xoops_module_header') ;
		$xoopsTpl->assign( 'xoops_module_header', $module_header . "\n" . $str );
	}
}

endif;
?>